home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_09_10
/
9n10091a
< prev
next >
Wrap
Text File
|
1980-01-01
|
1KB
|
81 lines
/*
listing 4 - lookup.c
*/
#include <stdio.h>
#include "common.h" /* define structures */
FUNC lookup (int type, struct record *position_ptr,
struct record *tran_start,
int transaction_size, void *user_value)
{
int i; /* loop control */
BOOL found=OFF; /* bool value for search lookup */
int integer; /* hold integer value */
float floater; /* hold float value */
switch (type) {
case INT:
for (i=0, integer = *((int *) position_ptr);
i < transaction_size; i++,
position_ptr++, integer = *((int *) position_ptr) ) {
if (integer == *( (int *) user_value) ) {
found = ON;
lookup_print(&tran_start[i]);
}
}
break;
case FLOAT:
for (i=0, floater = *((float *) position_ptr);
i < transaction_size; i++, position_ptr++,
floater = *((float *) position_ptr) ) {
if (floater == *( (float *) user_value) ) {
found = ON;
lookup_print(&tran_start[i]);
}
}
break;
case STRING:
for (i=0; i < transaction_size; i++, position_ptr++) {
if ( !strcmp( position_ptr, (char *) user_value) ) {
found = ON;
lookup_print(&tran_start[i]);
}
}
break;
};
/*
If a comparison was successful, then return SUCCEED, otherwise
return FAIL.
*/
if (!found) {
return FAIL;
} else {
return SUCCEED;
}
}